<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title">物流编辑</h4>
</div>
<form id="modify-form" action="/xqc/customer-delivery/delivery-fba-ajax" method="post" onsubmit="return checkModifyForm();">
    <div class="modal-body">
        <div class="row">
            <div class="form-group" style="padding-bottom: 30px;">
                <label style="padding-top: 8px;text-align: right;" class="col-sm-3 control-label">发货账号</label>
                <div class="col-sm-8">
{{--
                    <input type="text" class="form-control" name="param[account_id]" value="{{ $deliveryDetail->account->account ?: '' }}" placeholder="发货账号" readonly="readonly">
--}}
                    <select id="account_id_1" name="param[account_id]">
                        {{ getOptions(\App\Models\Basics\SysPlatAccount::getPlatAccountArray(), $deliveryDetail->account_id) }}
                    </select>
                </div>
            </div>
            <div class="form-group" style="padding-bottom: 30px;">
                <label style="padding-top: 8px;text-align: right;" class="col-sm-3 control-label">平台SKU</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" name="param[seller_sku]" value="{{ $deliveryDetail->seller_sku ?: '' }}" placeholder="商家SKU">
                </div>
            </div>
            <div class="form-group" style="padding-bottom: 30px;">
                <label style="padding-top: 8px;text-align: right;" class="col-sm-3 control-label">同步状态</label>
                <div class="col-sm-8">
                    <select id="sync_status_1" name="param[sync_status]" required>
                        {{ getOptions(\App\Models\CustomerDelivery\CustomerDeliveryDetail::$_syncStatus, $deliveryDetail->sync_status) }}
                    </select>
                </div>
            </div>
            <div class="form-group" style="padding-bottom: 30px;">
                <label style="padding-top: 8px;text-align: right;" class="col-sm-3 control-label">追踪号</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" name="param[tracking_no]" value="{{ $deliveryDetail->tracking_no ?: '' }}" placeholder="追踪号">
                </div>
            </div>
            <div class="form-group" style="padding-bottom: 30px;">
                <label style="padding-top: 8px;text-align: right;" class="col-sm-3 control-label">运输方式</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" name="param[logistics_type]" value="{{ $deliveryDetail->logistics_type ?: '' }}" placeholder="运输方式">
                </div>
            </div>
            <div class="form-group" style="padding-bottom: 30px;">
                <label for="total_weight" style="padding-top: 8px;text-align: right;" class="col-sm-3 control-label">发货公斤数</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control decimal_num_" id="total_weight" name="param[total_weight]" value="{{ $delivery->logistics->total_weight ?? '' }}" placeholder="发货公斤数">
                </div>
            </div>
            <div class="form-group" style="padding-bottom: 30px;">
                <label for="shipping_fee" style="padding-top: 8px;text-align: right;" class="col-sm-3 control-label">运费</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control decimal_num_" id="shipping_fee" name="param[shipping_fee]" value="{{ $delivery->logistics->shipping_fee ?? '' }}" placeholder="运费">
                </div>
            </div>
            <div class="form-group" style="padding-bottom: 30px;">
                <label for="other_fee" style="padding-top: 8px;text-align: right;" class="col-sm-3 control-label">关税+手续</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control decimal_num_" id="other_fee" name="param[other_fee]" value="{{ $delivery->logistics->other_fee ?? '' }}" placeholder="关税+手续">
                </div>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <input type="hidden" name="param[id]" value="{{ $id }}">
        <input type="hidden" name="action" value="doModify">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="submit" class="btn btn-primary">提交</button>
    </div>
</form>
<script language="JavaScript" type="text/javascript">
    function checkModifyForm(){
        let syncStatus = $('#sync_status_1').val();
        if(syncStatus == 1) {
            let trackingNo = $('input[name="param[tracking_no]"]').val().trim();
            if(trackingNo == ''){
                swal('追踪号不能为空', '', 'error');
                return false;
            }
            let logisticsType = $('input[name="param[logistics_type]"]').val().trim();
            if(logisticsType == ''){
                swal('运输方式不能为空', '', 'error');
                return false;
            }
        }
        return true;
    }

    $(function () {
        $('#account_id_1').select2({placeholder: '发货账号', allowClear: true,"width": '100%'});
        $('#sync_status_1').select2({placeholder: '同步状态', allowClear: true,"width": '100%'});
        $("#modify-form").ajaxForm(function (data) {
            if (typeof data === 'object') {
                if (data.status) {
                    $("#modifyModal").modal('hide');
                    $(".modal-backdrop").remove();
                    $('body').removeClass('modal-open');
                    toastr.success(data.message);
                    $.pjax.reload('#pjax-container');
                } else {
                    swal(data.message, '', 'error');
                }
            }
        });
    });
</script>
